package cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.activitys;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.R;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.base.BaseActivity;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.utils.Constance;
import cn.wuhan2019mwg.mobile.activity.wuhan2019mwg.views.Gradient;

/**
 * Created by dell on 2017/10/24.
 */

public class StartActivity extends BaseActivity implements View.OnClickListener {


//      private WebView wb_start;
//      private RoundProgress rp_skip;
//      private CustomVideoView videoview;

    private Gradient gradient;
    private int[] images = {R.mipmap.welcome_one, R.mipmap.welcome_two, R.mipmap.welcome_three, R.mipmap.welcome_four};
    private List<ImageView> imageViews = new ArrayList<>();

//      private AutoSwitchImageView asiv;

    private AppCompatButton acb_start;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_star;
    }

    @Override
    protected void initView() {

//        asiv = (AutoSwitchImageView) findViewById(R.id.asiv);
//        asiv.setImages(images).setIsCircle(true).startTask();

        imageViews.clear();
        acb_start = (AppCompatButton) findViewById(R.id.acb_start);
        acb_start.setOnClickListener(this);
        gradient = (Gradient) findViewById(R.id.gradient);
        for (int i = 0; i < images.length; i++) {
            ImageView imageView = new ImageView(StartActivity.this);
            imageView.setImageResource(images[i]);
            imageViews.add(imageView);
            if (imageViews.size() == 4) {
                break;
            }
        }
//        wb_start = (WebView) findViewById(R.id.wb_start);
//        videoview = (CustomVideoView) findViewById(R.id.videoview);
//        videoview.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.media));
//        videoview.start();
//        //循环播放
//
//        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//            @Override
//            public void onCompletion(MediaPlayer mediaPlayer) {
//
//                videoview.start();
//            }
//        });

//        rp_skip = (RoundProgress) findViewById(R.id.rp_skip);
//        rp_skip.setOnClickListener(this);

//        setWebClient();
    }

    @Override
    protected void initData() {
        gradient.setImageViews(imageViews);
        gradient.setTime(2000);

//
        handler.postDelayed(runnable, Constance.ENTER_TIME);
//        rp_skip.start();
    }

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            acb_start.setVisibility(View.VISIBLE);
        }
    };

//    private void setWebClient(){
//        wb_start.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//        wb_start.getSettings().setJavaScriptEnabled(true);// 设置可用JS
//        wb_start.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//        wb_start.getSettings().setPluginState(WebSettings.PluginState.ON);
//        wb_start.getSettings().setAllowFileAccess(true);
//        wb_start.getSettings().setDefaultTextEncodingName("UTF-8");
//        wb_start.getSettings().setLoadWithOverviewMode(true);
//        wb_start.getSettings().setUseWideViewPort(true);
//
//        WindowManager wm = (WindowManager) StartActivity.this.getSystemService(Context.WINDOW_SERVICE);
//        int width = wm.getDefaultDisplay().getWidth();
//        if(width > 650)
//        {
//            this.wb_start.setInitialScale(190);
//        }else if(width > 520)
//        {
//            this.wb_start.setInitialScale(160);
//        }else if(width > 450)
//        {
//            this.wb_start.setInitialScale(140);
//        }else if(width > 300)
//        {
//            this.wb_start.setInitialScale(120);
//        }else
//        {
//            this.wb_start.setInitialScale(100);
//        }
//
//
//        wb_start.setWebViewClient(new WebViewClient(){
//
//
//
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                    view.loadUrl(request.getUrl().toString());
//                    mUrl = request.getUrl().toString();
//                }
//
//                return true;
//            }
//
//            @Override
//            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                view.loadUrl(url);
//                mUrl = url;
//                Log.e("strurl", "String url " + url);
//                return true;
//            }
//
//            @Override
//            public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
//                super.onReceivedError(view, request, error);
//            }
//        });
//
//        wb_start.setWebChromeClient(new WebChromeClient(){
//
//            @Override
//            public void onProgressChanged(WebView view, int newProgress) {
//                super.onProgressChanged(view, newProgress);
//            }
//
//            @Override
//            public void onReceivedTitle(WebView view, String title) {
//                super.onReceivedTitle(view, title);
//
//            }
//        });
//        wb_start.loadUrl(mUrl);
//
//    }

    private Handler handler = new Handler();

    @Override
    protected void onStop() {
        super.onStop();
        handler.removeCallbacks(runnable);
//        rp_skip.stop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        finish();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {


//            case R.id.rp_skip:
//                handler.removeCallbacks(runnable);
//                rp_skip.stop();
//                Intent intent = new Intent();
//                intent.setClass(StartActivity.this, MainActivity.class);
//                startActivity(intent);
//                finish();
//                break;

            case R.id.acb_start:
                Intent intent = new Intent();
                intent.setClass(StartActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
                break;

        }
    }
}
